class Solution
{
public:
    int concatenatedBinary(int n)
    {
        long long result = 0;
        for (int i = 1; i <= n; ++i)
        {
            int bitCount = 32 - __builtin_clz(i);
            result = result << bitCount;
            result += i;
            result %= 1000000007;
        }
        return result;
    }
};